function loadAlbumCreation(target)
{
	Packages.system.mlf.GateKeeper.updateDynamicPortlet(target._parent, "app/vo/AlbumCreation.xml");
	dynamicPortletArr.chapterList="albumCreation";
}

function confirmAlbumCreation()
{
	var albumName_tf=Packages.system.mlf.GateKeeper.scanElement(this._name, "albumName");
	var albumName=albumName_tf.text;

	var defaultValue=Packages.system.mlf.GateKeeper.scanDictionary(albumName_tf, "AlbumNameValue");

	if (defaultValue.indexOf(albumName)>-1)
	{
		Packages.modula.MessageCenter.send("TEXTINPUT_REQUIRED", 1, 0);
		return;
	}
	
	var obj:Object=new Object();
	obj.memberId=Packages.model.UserProfile.data.memberId+"";
	obj.bookId=Packages.model.Context.address.id+"";
	obj.publicFlag=scopeOptValue.toString();
	obj.collabFlag=collabOptValue.toString();
	obj.name=albumName;
	if (scopeOptValue==3)
	{
		obj.publicGroupId=selectedScopeGroup.toString();
	}
	
	/*for (var a in obj)
	{
		Packages.log(a+": "+obj[a], "debug");
	}*/

	var data:Object=new Object();
	// data.path=target._parent;
	data.name="BookSpecial";
	data.container="chapterListContainer";
	data.oper="recordAlbumCreate";
	data.uri="app/content/bookPage/BookSpecial.xml";
	
	data.returnPath="loadChapterList";
	data.dynamicPortlet=dynamicPortletArr.chapterList;

	dynamicPortletArr.chapterList="commonRemotingResult";

	Packages.modula.RequestCommand.request("REMOTING", "recordAlbumCreate", obj, Packages.model.vo.CommonRemotingResultView, "normal", this, data);
}

function onAlbumCreationInit()
{
	var evtTargetArr:Array=new Array();
	evtTargetArr.push(Packages.system.mlf.GateKeeper.scanElement(this._name, "albumCreateConfirmSpot"));
	evtTargetArr.push(Packages.system.mlf.GateKeeper.scanElement(this._name, "albumCreateReturnSpot"));
	evtTargetArr.push(Packages.system.mlf.GateKeeper.scanElement(this._name, "noCollabOptSpot"));
	evtTargetArr.push(Packages.system.mlf.GateKeeper.scanElement(this._name, "collabOptSpot"));
	evtTargetArr.push(Packages.system.mlf.GateKeeper.scanElement(this._name, "privateScopeOptSpot"));
	evtTargetArr.push(Packages.system.mlf.GateKeeper.scanElement(this._name, "friendScopeOptSpot"));
	evtTargetArr.push(Packages.system.mlf.GateKeeper.scanElement(this._name, "groupScopeOptSpot"));
	evtTargetArr.push(Packages.system.mlf.GateKeeper.scanElement(this._name, "publicScopeOptSpot"));
	Packages.system.events.StateFulButtonEvent.initialize(evtTargetArr);

	// default setting
	var noCollabOptSpot=Packages.system.mlf.GateKeeper.scanElement(this._name, "noCollabOptSpot");
	switchCollabOption(noCollabOptSpot);
	var privateScopeOptSpot=Packages.system.mlf.GateKeeper.scanElement(this._name, "privateScopeOptSpot");
	switchScopeOption(privateScopeOptSpot);
}

function switchCollabOption(target)
{
	if (target._name=="noCollabOptSpot")
	{
		collabOptValue=1;
	}
	else if (target._name=="collabOptSpot")
	{
		collabOptValue=2;
	}
	Packages.system.events.StateFulButtonEvent.createSelectedSpot(target);
}

function switchScopeOption(target)
{
	var scopeGroup=Packages.system.mlf.GateKeeper.scanElement(this._name, "scopeGroup");
	scopeGroup._visible=false;
	
	if (target._name=="privateScopeOptSpot")
	{
		scopeOptValue=1;
		var noCollabOptSpot=Packages.system.mlf.GateKeeper.scanElement(this._name, "noCollabOptSpot");
		switchCollabOption(noCollabOptSpot);
	}
	else if (target._name=="friendScopeOptSpot")
	{
		scopeOptValue=2;
	}
	else if (target._name=="groupScopeOptSpot")
	{
		scopeOptValue=3;
		displayRelatedGroups();
	}
	else if (target._name=="publicScopeOptSpot")
	{
		scopeOptValue=4;
	}
	Packages.system.events.StateFulButtonEvent.createSelectedSpot(target);
}

function displayRelatedGroups()
{
	var scopeGroup=Packages.system.mlf.GateKeeper.scanElement(this._name, "scopeGroup");
	scopeGroup._visible=true;
	
	Packages.modula.RequestCommand.request("HTTP", "restlet/members/me/groups", null, Packages.model.vo.GroupListView, "albumGroupMode", this, {container:"chapterListContainer", dynamicPortlet:dynamicPortletArr.chapterList, slot:this._name, uri:"app/content/bookPage/BookSpecial.xml"});
}